package com.fenger.bus.service.impl;

import com.fenger.bus.domain.Provider;
import com.fenger.bus.mapper.ProviderMapper;
import com.fenger.bus.service.ProviderService;
import com.fenger.bus.vo.ProviderVo;
import com.fenger.sys.contast.SysConstast;
import com.fenger.sys.utils.DataGirdView;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ProviderServiceImpl implements ProviderService {

    @Autowired
    ProviderMapper providerMapper;

    @Override
    @Transactional(readOnly = true)
    public DataGirdView queryAllProvider(ProviderVo providerVo) {
        Page<Object> page = PageHelper.startPage(providerVo.getPage(), providerVo.getLimit());
        List<Provider> providers = this.providerMapper.queryAllProvider(providerVo);

        return new DataGirdView(SysConstast.SUCCESS_CODE,SysConstast.SUCCESS_MSG,page.getTotal(),providers);
    }

    @Override
    public void addProvider(ProviderVo providerVo) {
        this.providerMapper.insertSelective(providerVo);
    }

    @Override
    public void updateProvider(ProviderVo providerVo) {
        this.providerMapper.updateByPrimaryKeySelective(providerVo);
    }

    @Override
    public void deleteProvider(Integer id) {
        this.providerMapper.deleteByPrimaryKey(id);
    }
}
